<template>
    <div class="app-container">
        <el-form ref="elForm" :model="formData" :disabled="$route.query.isInfo" :rules="rules" size="medium"
            label-width="100px">
            <h2 style="text-align: center">首页大厅设置</h2>
            <h4 class="form-header h4">文字滚动</h4>
            <el-row>
                <el-col :span="6">
                    <el-form-item label="选择模块" prop="projectName">
                        <el-select v-model="formData.type" placeholder="请选择项目名称" clearable :style="{ width: '100%' }"
                            @change="changeType">
                            <el-option label="滚动文字" :value="2" />
                            <el-option label="轮播图片" :value="1" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="20" v-if="formData.type == 2">
                    <el-form-item label="文字滚动" prop="content">
                        <el-input v-model="formData.content" type="textarea" placeholder="请输入首页滚动文字" clearable
                            :style="{ width: '100%' }">
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="20" v-if="formData.type == 1">
                    <el-form-item label="轮播图设置" prop="content">
                        <FileUpload :limit="1" :fileType="fileType" v-model="formData.content"></FileUpload>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-col :span="24">
                <el-form-item label-width="0" style="text-align: center; margin-top: 30px">
                    <el-button v-if="!$route.query.isInfo" type="primary" @click="submitForm">提交</el-button>
                    <el-button :disabled="false" @click="resetForm">返回</el-button>
                </el-form-item>
            </el-col>
        </el-form>
    </div>
</template>
  
<script>
import store from "@/store";
import {
    advIndexBannerAdd,
    advIndexBannerEdit,
    advIndexBannerInfo
} from "@/api/business/hall.js";
export default {
    name: "AddBxgl",
    components: {},
    dicts: ["sys_fee_subject", "sys_fee_type"],

    props: [],
    data() {
        return {
            fileType: ["png", "jpge", "jpg",],
            totalFee: 0,
            name: store.getters.name,
            formData: {
                type: 1,
                projectName: undefined,
                content:''
            },
            projectList: [],
            rules: {
                content: [
                    {
                        required: true,
                        message: "请选择",
                        trigger: "blur",
                    },
                ],

            },
        };
    },
    computed: {},

    created() {
        // this.getUser();
        this.formData.advIndexBannerId = this.$route.query.id
        if (this.$route.query.isEdit || this.$route.query.isInfo) {
            this.getprojectInfo();
        }
    },
    mounted() {
    },
    methods: {
        getprojectInfo() {
            advIndexBannerInfo(this.$route.query.id).then((response) => {
                console.log(response);
                this.formData = response.data;
            });
        },
        changeType() {
            this.formData.content = ''
        },
        changeUser(e) {
            console.log(e);
            this.formData.applyUserName = e.nickName;
            this.formData.deptName = e.dept.deptName;
            this.formData.deptId = e.deptId;
        },
        submitForm() {
            this.$refs["elForm"].validate((valid) => {
                if (valid) {
                    let query = JSON.parse(JSON.stringify(this.formData));
                    if (this.formData.advIndexBannerId != undefined) {
                        advIndexBannerEdit(query).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.resetForm();
                        });
                    } else {
                        advIndexBannerAdd(query).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.resetForm();
                        });
                    }
                }
            });
        },
        resetForm() {
            this.$tab.closeOpenPage();
        },
    },
};
</script>
  